<?php
/**
 * @return
 * @author 朱乐斌
 * @date
 */

namespace app\api\controller;

use app\api\model\ActivityRegisterModel;
use app\api\validate\IndexValidate;
use app\BaseController;
use think\Exception;

class ActivityRegister extends BaseController
{

    // 报名
    public function index()
    {
        try {
            //接收数据
            $data = $this->request->param();
            //验证数据
            $validate = new IndexValidate();
            $result = $validate->scene('register')->check($data);
            if ($result !== true) {
                $this->error($validate->getError());
            }

            /*
             * 此处应有短信验证码验证
             * 代码.....
             */

            //查询是否已经报名
            $model = new ActivityRegisterModel();
            if ($model->where('mobile', $data['mobile'])
                ->where('activity_id', $data['activity_id'])
                ->find()) {
                $this->error('您已经报名过了');
            } else {
                $model->save($data);
                $this->success('报名成功');
            }
        } catch (Exception $e) {
            $this->error('', $e->getMessage());
        }
    }

}